package com.zzh.service;

import com.zzh.dao.mapper.UserMapper;
import com.zzh.entity.UserEntity;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserService {

    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private UserMapper userMapper;
//    /***
//     *
//     * 插入数据到User表中
//     *
//     */
//    @RequestMapping("/insertUser")
//    public String insertUser(String name, Integer age) {
//        int update = jdbcTemplate.update("insert into users values(null,?,?);", name, age);
//        return update > 0 ? "sucess" : "fali";
//    }

    /***
     * @param id
     * @return
     * 参数
     */
    @RequestMapping("/mybatisfinbyId")
    public UserEntity mybatisfinbyId(Integer id) {
        return userMapper.selectByUserId(id);
    }

    @RequestMapping("/insertUser")
    public int insertUser(String userName, Integer age) {
        return userMapper.insertUser(userName, age);
    }

    @RequestMapping("/getUserList")
    public List<UserEntity> getUserList() {
        return userMapper.getUserList();
    }
}